from flask import Blueprint, request, jsonify
import pandas as pd
from methods.boku import boku_rg

bp = Blueprint("boku", __name__, url_prefix="/boku")


@bp.route('/retGoodsByExcel', methods=['post'])
def retGoodsByExcel():
    # 1、判断是否上传文件以及必填参数
    if 'file' not in request.files:
        return jsonify({'message': '请上传文件！', 'code': 400})

    file = request.files['file']

    if file.filename == '' or '.' not in file.filename or file.filename.rsplit('.', 1)[1].lower() not in {'xlsx'}:
        return jsonify({'message': '请上传正确的Excel文件！', 'code': 400})

    form = request.form
    if 'username' not in form or 'password' not in form or 'type' not in form:
        return jsonify({'message': '请填写用户名密码以及类型！', 'code': 400})

    # 2、调用方法 type=1退货，type=0查询退货情况
    data = boku_rg(file, form)
    return jsonify(data)


@bp.route('/test', methods=['get'])
def test():
    return "test"
# [].filter(item => {
#         return item.orderInfo.orderNum.includes('DE') && item.orderInfo.message!=='退货成功！'
# })
